import { Body, Controller, Get, Post, UseGuards } from '@nestjs/common';
import { AuthService } from './auth.service';
import { LoginAuthDto } from './dto/login.dto';
import { CreateAuthDto } from './dto/create-auth.dto';
import { getUserInfo } from 'src/utils/custom-decorators';
import { AuthGuard } from 'src/gurad/auth/auth.guard';

@Controller('auth')
export class AuthController {
  constructor(private readonly authService: AuthService) {}
  /**
   * 登录
   */
  @Post('login')
  login(@Body() loginAuthDto: LoginAuthDto) {
    return this.authService.login(loginAuthDto);
  }

  /**
   * 注册
   */
  @Post('registry')
  registry(@Body() createAuthDto: CreateAuthDto) {
    return this.authService.register(createAuthDto);
  }

  /**
   * 获取用户的角色
  */
  @UseGuards(AuthGuard)
  @Get('role')
  getRole(@getUserInfo('role') role: string) {
    return this.authService.getRole(role)
  }
}
